package pers.rain.WebMagicDemo.Dao.impl;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import pers.rain.WebMagicDemo.Bean.WebBooks;
import pers.rain.WebMagicDemo.Dao.WebBooksDao;

public class WebBooksDaoImpl implements WebBooksDao{

	@Override
	public int countAllWeb() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public WebBooks queryWebBook(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int insertWebBook(WebBooks webbook) {
		// TODO Auto-generated method stub
		
		String resource="mybatis_config.xml";
        Reader reader=null;
        SqlSessionFactory  ssf=null;
        SqlSession session=null;
        int count=0;
        try {
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            ssf = builder.build(reader);
            session=ssf.openSession();
            count=session.insert("pers.rain.WebMagicDemo.Dao.WebBooksDao.insertWebBook",webbook);
            
            session.commit();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally{
            session.close();
        }
        return count;
	}

	@Override
	public int deleteWebBook(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateWebBook(WebBooks webbook) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<WebBooks> getAllWebBooks() {
		// TODO Auto-generated method stub
		return null;
	}

	
}
